package com.example.opengldemo.bullet;

import java.io.File;
import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

import android.content.Context;

import android.os.Environment;




public class CopyAssetFileToSDCard {
	private Context context;
	public  CopyAssetFileToSDCard(Context context)
	{
		this.context = context;
	}
	public  void copy(String assetFilePath,String SDcardFilePath,String copyFileName) throws IOException {

		File sdcardDir = Environment.getExternalStorageDirectory();
		File data = null;
		if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
		{

			String path = sdcardDir.getPath()+SDcardFilePath;
			File folder = new File(path);
			data = new File(path,copyFileName);
			if(!folder.exists())
			{
				folder.mkdirs();
			}
			if(!data.exists())
			{
				data.createNewFile();
			}
		}
		InputStream myInput;
		OutputStream myOutput = new FileOutputStream(data);
		myInput = context.getAssets().open(assetFilePath);
		byte[] buffer = new byte[1024];
		int length = myInput.read(buffer);
		while(length > 0)
		{
			myOutput.write(buffer,0,length);
			length = myInput.read(buffer);
		}
		myOutput.flush();
		myInput.close();
		myOutput.close();
	}
}
